package com.sharp.portal.dao.repository;

import com.sharp.kernel.constant.CommonConst;
import com.sharp.kernel.mybatis.repository.BaseMysqlRepository;
import com.sharp.portal.dao.entity.CoPortalLayout;
import com.sharp.portal.dao.mapper.CoPortalLayoutDao;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * Title: CoPortalLayoutService
 * Description: Copyright: Copyright (c) 2022 Company: Sharp Ltd.
 *
 * @author Sharp
 * @date 2022/09/26 22:47
 */
@Service
public class CoPortalLayoutService extends BaseMysqlRepository<CoPortalLayout, CoPortalLayoutDao> {

    @Resource
    private CoPortalLayoutDao coPortalLayoutDao;

    public List<CoPortalLayout> getPortalLayoutByPath(String path) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("path", path);
        example.orderBy("displayOrder").asc();
        return super.select(example);
    }

    public CoPortalLayout getPortalLayoutPidField(String path) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("path", path);
        criteria.andEqualTo("pidField", CommonConst.YES);
        return super.selectOne(example);
    }

    public CoPortalLayout getPortalLayoutIdField(String path) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("path", path);
        criteria.andEqualTo("idField", CommonConst.YES);
        return super.selectOne(example);
    }

    public CoPortalLayout getPortalLayoutDisplayField(String path) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("path", path);
        criteria.andEqualTo("displayField", CommonConst.YES);
        return super.selectOne(example);
    }

    public void deleteByPortalPath(String path) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("path", path);
        super.delete(example);
    }
}
